/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.*;
import java.util.function.UnaryOperator;

/**
 * <p>Project: javase - Lambda2
 * <p>Powered by webrx On 2021-12-21 11:11:39
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Lambda2 {
    public static void main(String[] args) {
        var nums = new Integer[]{1, 10, 2, 5, 3, 20, 11};
        System.out.println(Arrays.toString(nums));
        int i = 3;
        //升序
        //Arrays.sort(nums, (a, b) -> a - b);
        //Arrays.sort(nums, Comparator.comparingInt(a -> a));
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));

        //降序
        Arrays.sort(nums, (a, b) -> b - a);
        System.out.println(Arrays.toString(nums));

        //乱序
        Random rand = new Random();
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? -1 : 1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? -1 : 1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? -1 : 1);
        Arrays.sort(nums, (a, b) -> rand.nextBoolean() ? -1 : 1);
        System.out.println(Arrays.toString(nums));

        //Array 转换为 List 使用 shuffle打乱顺序，并转换为Array
        var list = new ArrayList<>(Arrays.stream(nums).toList());
        Collections.shuffle(list);
        list.toArray(nums);
        System.out.println(Arrays.toString(nums));
    }
}
